package com.ruoyi.web.controller.weiriya;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.weiriya.domain.WDoor;
import com.ruoyi.weiriya.service.IWDoorService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 门禁Controller
 * 
 * @author ruoyi
 * @date 2023-08-24
 */
@Api(tags = "门禁管理")
@RestController
@RequestMapping("/system/door")
public class WDoorController extends BaseController
{
    @Autowired
    private IWDoorService wDoorService;

    /**
     * 查询门禁列表
     */
    @ApiOperation("获取门禁列表")
    @PreAuthorize("@ss.hasPermi('system:door:list')")
    @GetMapping("/list")
    public TableDataInfo list(WDoor wDoor)
    {
        startPage();
        List<WDoor> list = wDoorService.getList(wDoor);
        return getDataTable(list);
    }

    /**
     * 导出门禁列表
     */
    @ApiOperation("导出门禁列表")
    @PreAuthorize("@ss.hasPermi('system:door:export')")
    @Log(title = "门禁", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WDoor wDoor)
    {
        List<WDoor> list = wDoorService.getList(wDoor);
        ExcelUtil<WDoor> util = new ExcelUtil<WDoor>(WDoor.class);
        util.exportExcel(response, list, "门禁数据");
    }

    /**
     * 导入门禁列表
     */
    @ApiOperation("导入门禁列表")
    @PreAuthorize("@ss.hasPermi('system:door:import')")
    @Log(title = "门禁", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<WDoor> util = new ExcelUtil<WDoor>(WDoor.class);
        List<WDoor> list = util.importExcel(file.getInputStream());
        return success(wDoorService.saveBatch(list));
    }

    /**
     * 获取门禁详细信息
     */
    @ApiOperation("获取门禁详细")
    @ApiImplicitParam(name = "id", value = "门禁ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('system:door:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wDoorService.getWDoorById(id));
    }

    /**
     * 新增门禁
     */
    @ApiOperation("新增门禁")
    @PreAuthorize("@ss.hasPermi('system:door:add')")
    @Log(title = "门禁", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WDoor wDoor)
    {
        return toAjax(wDoorService.save(wDoor));
    }

    /**
     * 修改门禁
     */
    @ApiOperation("更新门禁")
    @PreAuthorize("@ss.hasPermi('system:door:edit')")
    @Log(title = "门禁", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WDoor wDoor)
    {
        return toAjax(wDoorService.updateById(wDoor));
    }

    /**
     * 删除门禁
     */
    @ApiOperation("删除门禁")
    @ApiImplicitParam(name = "ids", value = "门禁ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('system:door:remove')")
    @Log(title = "门禁", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(wDoorService.removeByIds(ids));
    }
}
